import { Component, OnInit,Input } from '@angular/core';
import { TipService, ModalTipService, ModalService ,HttpService} from 'itcloud-plugin';
import { GetPathService } from '../../get-path.service';
import { Router} from '@angular/router'; //导入router服务

@Component({
  selector: 'app-view-notice',
  templateUrl: './view-notice.component.html',
  styleUrls: ['./view-notice.component.css']
})
export class ViewNoticeComponent implements OnInit {

  @Input() handler;
  @Input() data;

  replyContent:string;
  fileTodoId;
  fileInfoId;
  infoName;
  public viewNotice:any={};
  public viewNoticeFiles:any={};
  constructor(private http: HttpService,
              private tipService: TipService,
              private GetPathService: GetPathService,
              private router: Router
  ) { }
  /*
   获取列表公告数据
   * */
  requestData() {
    const param = {
      id: 3
    };
    this.http.getData({
      url: this.GetPathService.AjaxPath.bulletinServer+`/mineTodo/getMineTodoById?id=${this.data.infoTodoId}`,
      save: param,
    }).subscribe(res => {
      this.viewNotice=res['bean'].info;
      this.viewNoticeFiles=res['bean'];
      this.replyContent=this.viewNotice.todoReplyContent;
      if(this.viewNotice.infoContent==null){
          this.viewNotice.infoContent="";
      }

      if(this.viewNotice.infoType==0){
          this.infoName=`关于${this.viewNotice.infoName}的公告通知`;
      }else if(this.viewNotice.infoType==1){
          this.infoName=`关于${this.viewNotice.infoName}的信息交流`;
      }
      for(let i=0;i<this.viewNoticeFiles.todoAtts.length;i++){
      this.fileTodoId=this.viewNoticeFiles.todoAtts[i].id;

      }
      for(let i=0;i<this.viewNoticeFiles.todoAtts.length;i++){
        this.fileInfoId=this.viewNoticeFiles.infoAtts[i].id;
      }
    }, err => {
      console.log(err.returnMessage)
    });
  }
    /*取消点击关闭*/
    closeDrawer() {
        this.handler&& this.handler();
    }
  /***
   * 时间转换
   *
   *
   * */
  timeStamp(timestamp){
      let Y,M,D,h,m,s;
      let date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
      //var date = new Date(timestamp * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
      Y = date.getFullYear() + '-';
      M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
      D = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate()) + ' ';
      h = (date.getHours() < 10 ? '0'+ date.getHours() : date.getHours()) + ':';
      m = (date.getMinutes() < 10 ? '0'+ date.getMinutes() : date.getMinutes()) + ':';
      s = (date.getSeconds()< 10 ? '0'+ date.getSeconds() : date.getSeconds());
      return Y+M+D+h+m+s;
  }
  /*附件大小转化*/
  conver(limit){
    let size = "";
    if( limit < 0.1 * 1024 ){ //如果小于0.1KB转化成B
      size = limit.toFixed(2) + "B";
    }else if(limit < 0.1 * 1024 * 1024 ){//如果小于0.1MB转化成KB
      size = (limit / 1024).toFixed(2) + "KB";
    }else if(limit < 0.1 * 1024 * 1024 * 1024){ //如果小于0.1GB转化成MB
      size = (limit / (1024 * 1024)).toFixed(2) + "MB";
    }else{ //其他转化成GB
      size = (limit / (1024 * 1024 * 1024)).toFixed(2) + "GB";
    }

    let sizestr = size + "";
    let len = sizestr.indexOf("\.");
    let dec = sizestr.substr(len + 1, 2);
    if(dec == "00"){//当小数点后为00时 去掉小数部分
      return sizestr.substring(0,len) + sizestr.substr(len + 3,2);
    }
    return sizestr;
  }


  ngOnInit() {
    //this.getHeaderr();
    this.requestData();

    //console.log(this.data)
  }

}
